from typing import Any, Dict, List
from fastapi_amis_admin import admin
from fastapi_amis_admin.admin import (
    AdminApp,
    FieldPermEnum,
    RecentTimeSelectPerm,
    SimpleSelectPerm,
    UserSelectPerm,
)
from fastapi_amis_admin.amis.components import PageSchema, TableColumn, Service, Action
from fastapi_amis_admin.crud.parser import LabelField, PropertyField
from fastapi_amis_admin.models import Field
from fastapi_user_auth.auth.models import User, Role
from fastapi_user_auth.mixins.admin import AuthFieldModelAdmin, AuthSelectModelAdmin
from pydantic import BaseModel
from starlette.requests import Request
from sqlmodel import select
#from core.globals import site
from fastapi_amis_admin import admin
from apps.audit.models import AuditLog

# 注册审计日志ModelAdmin
#@site.register_admin
class AuditLogAdmin(admin.ModelAdmin):
    page_schema = "数据操作日志"
    # 配置管理模型
    model = AuditLog
    # 设置为只读模式，不允许编辑审计日志
    readonly = True
    # 显示项目操作作为列
    display_item_action_as_column = True
    # 配置列表页面
    list_display = ["id", "username", "operation_type", "table_name", "record_id", "operation_time", "ip_address"]
    # 配置搜索字段
    search_fields = ["username", "operation_type", "table_name"]
    # 配置过滤字段
    filters = ["operation_type", "table_name", "operation_time"]
    # 配置排序字段
    sort_fields = ["operation_time"]